efform_onload = function ()
{
	$('#result_add-0-fdJxBm').val($('#fdCreateDepartmentId').val());
}
/*根据主表查询明细*/
efgrid_onRowClicked = function( grid_id, row_index ){ 
	if(grid_id == "ef_grid_result"){ 
		var grid = efgrid.getGridObject(grid_id); 
		var selectedRow=grid.getRowData(row_index);
		for(var item in selectedRow){
			var colname=item;
			var colvalue=selectedRow[item];
			$('#ef_region_mainadd').find('#result_add-0-'+colname).val(colvalue);
		} 
		
	}
}


var ajax_callback = {
		onSuccess : function(eiInfo) {
			var grid = efgrid.getGridObject("ef_grid_result");
			grid.refresh(eiInfo);
			clearAfterSolve("ef_region_mainadd");
		}, 
		onFail:function(eMsg)
		{
			alert("确认失败，原因："+eMsg);
		}

}	

button_insert_onclick = function (){
	check();
	var info = getDetail("ef_region_mainadd","result_add");
	if (null != info) {
		EiCommunicator.send("ZMCK50", "insert", info, ajax_callback);
}
}

//var ajax_callback1 = {
//		onSuccess: function(eiInfo) {
//			if(eiInfo.status>=0)
//			{
//
//			}
//		},
//		onFail:function(eMsg)
//		{
//			alert("确认失败，原因："+eMsg);
//		}
//	 
//	}

button_update_onclick = function (){
	check();
	
	var info = getDetail("ef_region_mainadd","result_add");	
	var status=$('#result_add-0-fdStatus').val();

	if (null != info && status != "上报" ) {
		
		EiCommunicator.send("ZMCK50", "update", info, ajax_callback);
	} else{
		EFAlert("只能对草拟的记录进行修改！"); return;
	} 
}


button_query_onclick = function (){
	efgrid.submitInqu( "ef_grid_result", "ZM","ZMCK50","query");
}

button_delete_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行删除！"); return;
		}
	}
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCK50","delete",true);
	}); 
}


button_report_onclick = function (){
	if (isSelected("ef_grid_result") == 0)return; 
	EFConfirm('确认要上报吗?', '确认框', function(r) {
		efgrid.submitForm( "ef_grid_result", "ZM","ZMCK50","report",true);
	});
}

//非空校验，日期校验
check = function()
{
    
    var fdJxTime = $('#result_add-0-fdJxTime').val();//调度日期
    var fdCurrentDate = $('#result_add-0-fdCurrentDate').val();//当前日期
    if(fdCurrentDate < fdJxTime){
    	alert("检修日期不能晚于当前日期");return;
    }
	
	var ei_info=new EiInfo();
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('result_add').getRows(0)[0][3].trim()==""){
		EFAlert("当前日期不能为空");
		return;
	}	
	if(ei_info.getBlock('result_add').getRows(0)[0][4].trim()==""){
		EFAlert("检修日期不能为空");
		return;
	}	
	if(ei_info.getBlock('result_add').getRows(0)[0][1].trim()==""){
		EFAlert("检修部门不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][6].trim()==""){
		EFAlert("检修内容不能为空");
		return;
	}	
}


/**
 * 操作完成后清空该region内的各数据项的值
 */
var clearAfterSolve=function(region) { 
	var temp;
	//遍历INPUT
	$('#'+region).find("input").each(function (){
		temp = $(this).attr("id");
		$('#'+temp).val("");
//		$(this).removeData();
	});
	//遍历SELECT
	$('#'+region).find("select").each(function (){
		temp = $(this).attr("id");
		$('#'+temp).val("");
	});
	//遍历TEXTAREA
	$('#'+region).find("textarea").each(function (){
		temp = $(this).attr("id");
		$('#'+temp).val("");
	});
};



